package cn.usian.common.exception;

import cn.usian.jyzx.model.vo.common.Result;
import cn.usian.jyzx.model.vo.common.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 处理异常
 * 拦截带有@RestController的类  controller
 *
 * //想知道有没有抛异常， 异常类型
 * @TODO:
 * @Author:baimu
 * @Date:2024 11 05 09 47
 **/
@RestControllerAdvice
@Slf4j
public class GlobalException {


    /**
     * 只要 异常类型JyzxException
     * @param e
     * @return
     */
    @ExceptionHandler(JyzxException.class)
    public Result handleException(JyzxException e){
        log.info("捕获到异常了---------JyzxException code：{},message:{}",e.getResultCodeEnum().getCode(),e.getResultCodeEnum().getMessage());
        return Result.build(null, ResultCodeEnum.VERIFICATION_CODE_SERROR);

    }

    @ExceptionHandler(LoginException.class)
    public Result handleLoginException(LoginException e){
        log.info("捕获到异常了---------LoginException code：{},message:{}",e.getResultCodeEnum().getCode(),e.getResultCodeEnum().getMessage());
        return Result.build(null, e.resultCodeEnum);

    }

    @ExceptionHandler(OrderException.class)
    public Result handleOrderException(OrderException e){
        log.info("捕获到异常了---------OrderException code：{},message:{}",e.getResultCodeEnum().getCode(),e.getResultCodeEnum().getMessage());
        return Result.build(null, e.resultCodeEnum);

    }
}
